In OPC UA, the IEasyUAClientConnectionMonitoring service that you can obtan from the EasyUAClient object provides a ServerConditionChanged event. This event is raised for a change in the condition of an OPC server. Specifically, you receive a notification whenever the connection to the server is established, or whenever the connection is terminated. Whenever there an error (exception) associated with the server condition, it is also available in the event arguments.
The event notification passes to you an EasyUAServerConditionChangedEventArgs object, which contains data about the new server condition. The EndpointDescriptor property identifies the server the notification applies to. The Boolean Connected property indicates whether the server is now connected. The Exception property contains a null reference in case of no error, or it contains an exception object in case of problems.
Additional properties of the event arguments distinguish the change further. For example, the ConnectionState property contains an enumerated value (ConnectionState Enumeration) with members Disconnected, Connecting, Connected, and Disconnecting. The RetrialDelay property (valid in the Disconnected state) indicates the time (in milliseconds) to the next reconnection attempt.
The Statistics Property of the EasyUAServerConditionChangedEventArgs Class contains a ConnectedConditionStatistics object, with large amount of information about the connection to the server. There is a sequential connection attempt count, and an AutomatonStateStatistics object for each of the connection states (Disconnected, Connecting, Connected, and Disconnecting, of ConnectionState Enumeration), and for an "Unconnected" state, which represents a state other than Connected. For each of these states, you can obtain information such as how many time it was entered, when it was first entered, when the last cycle started and how long it did last, what is the minimum, maximum, and accumulated duration of the state, and much more. For the current state, you can also obtain information such as when it was entered and how long it is active.
Note that the information provided by this event should be used for oversight, informational and diagnostics purposes only. Specifically, you should not use it to attempt to implement any error recovery mechanism, because error recovery is already built into the OPC Data Client software, and having your own mechanism would inevitably cause conflicts.
A corresponding service and event is not currently available for OPC Classic.